import { WeaSearchGroup,WeaFormItem ,WeaProgress,WeaRichText,WeaUpload,WeaLocaleProvider,WeaError} from 'ecCom';
import { Button,Row,Col,InputNumber,Tooltip } from 'antd';
import {toJS} from "mobx"
import {WeaSwitch} from "comsMobx"
import {observer} from 'mobx-react';

const view_basicToolBar = {
    uploadUrl: "/api/blog/fileupload/uploadimage", 
    startupFocus: false,
    toolbar: [],
  };

const basicToolBar = {
    uploadUrl: "/api/blog/fileupload/uploadimage", 
    startupFocus: false,
    toolbar: [
      { name: 'markdown', items: ['Markdown'] },
      { name: 'document', items: ['Source', '-', 'Save', 'NewPage', 'Preview',  '-', 'Templates'] },
      { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
      { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] },
      { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
      { name: 'colors', items: ['TextColor', 'BGColor'] },
      { name: 'tools', items: ['Maximize', 'ShowBlocks'] },
      { name: 'insert', items: ['Image', 'Table', 'Smiley'] }
    ],
  };

const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class ProjectCondition extends React.Component{
    constructor(props) {
        super(props);
        this.formParams = {};
     }
    render(){
        const { fieldInfo, form,setFormFields,setValidate } = this.props;
        const {isFormInit} = form;
        let group = [];
        const formParamsTemp = form.getFormParams();
        for(let param in formParamsTemp){
            this.formParams[param] = formParamsTemp[param];
        }
        isFormInit &&  fieldInfo.map((c,i) =>{
          let items = [];
          c.items.map(fields => {
            let hide = false;
            let dom;
            let hasunderline = false;
            //只读样式控制
            let stylecss = {'margin-right':'5px','margin-top': '6px'};
            if(fields.viewAttr == "1" || (fields.conditionType == "BROWSER" && fields.browserConditionParam.viewAttr == "1")) {
                hasunderline = true;
                stylecss = {'margin-right':'5px','margin-top': '16px'};
            }
            if(fields.viewAttr == "1" || (fields.conditionType == "BROWSER" && fields.browserConditionParam.viewAttr == "1")) {hasunderline = true}  //只读样式控制
            if(fields.domkey[0] == "prjprocess"){
                if(fields.viewAttr == "1"){
                    dom = <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@lqf4hk@${fields.domkey[0]}`}>
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@qmmp9n@${fields.domkey[0]}`} span={12} style={stylecss}>
                        <WeaProgress ecId={`${this && this.props && this.props.ecId || ''}_WeaProgress@ovfdk4@${fields.domkey[0]}`} name={fields.domkey[0]} percent={fields.value || 0} status="active"  />
                    </Col>
                  </Row>
                }else{
                    dom = <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@zxpuo7@${fields.domkey[0]}`}>
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@g54779@${fields.domkey[0]}`} span={24} style={stylecss}>
                        <InputNumber ecId={`${this && this.props && this.props.ecId || ''}_InputNumber@dph2b5@${fields.domkey[0]}`} name={fields.domkey[0]} min={0} max={100} defaultValue={0} formatter={value=>`${value}%`} parser={value =>value.replace('%','')} onChange={(v)=>{setFormFields({finish:{value:v}})}} />
                        <span style={{marginLeft:5,marginTop:6}}>%</span>
                    </Col>
                  </Row>    
                }
            }else if(fields.conditionType == "RICHTEXT"){
                if(fields.viewAttr == "1"){
                    dom = <div className='view_basicToolBar'><WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@9ulp9n@${fields.domkey[0]}`} fieldConfig={{...fields,ckConfig:view_basicToolBar}} form={form}/></div>
                }else{
                    dom = <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@8r33au@${fields.domkey[0]}`} fieldConfig={{...fields,ckConfig:basicToolBar}} form={form}/>
                }
            }else if(fields.conditionType == "ATTACHEMENT"){
                let domkey = fields.domkey[0];
                dom = <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@ymxdhi@${fields.domkey[0]}`}>
                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@vmn86j@${fields.domkey[0]}`} span={24} style={stylecss}>
                    <WeaUpload ecId={`${this && this.props && this.props.ecId || ''}_WeaUpload@aysgqy@${fields.domkey[0]}`} 
                        name={domkey}
                        uploadId={[domkey]}
                        uploadUrl={"/api/proj/prjutil/fileUpload?accsec="+fields.accsec}
                        category={fields.accsec}
                        autoUpload={true}
                        showBatchLoad={false}
                        showClearAll={false}
                        multiSelection={true}
                        datas={toJS(fields.datas)}
                        maxUploadSize={fields.accsize}
                        onChange={v => {setFormFields({[domkey]:{value:v}})}}
                        viewAttr={fields.viewAttr}
                        // onUploading={(state)=>{}}
                    />
                </Col>
              </Row>   
            }else{
                dom =  <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@5ucfzu@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams}/>; 
            }
            if(fields.domkey[0] == "members" || fields.domkey[0] == "hrmids02"){
                if(hasunderline){
                    items.push({
                        com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5f275t@${fields.domkey[0]}`}
                            colon={false}
                            label={<span>
                                {fields.label+" :"}
                                {(fields.browserConditionParam.viewAttr == 1 ? "" :
                                <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@z2wrsq@${fields.domkey[0]}`} placement="bottom" title={getLabel(383844,"项目人员默认保存时将任务负责人同步至项目成员")}>
                                    <span className={`icon-coms-Explain`} style={{marginLeft:"10px",color:"#fa0",fontSize:"14px"}} />
                                </Tooltip>)}
                            </span>}
                            labelCol={{span: `${fields.labelcol}`}}
                            error={form.getError(fields)}
                            tipPosition="bottom"
                            wrapperCol={{span: `${fields.fieldcol}`}} underline>
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@6f7ku2@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams}/>
                            </WeaFormItem>),
                        colSpan:1,
                        hide:hide
                    });
                }else{
                    items.push({
                        com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@gs0wks@${fields.domkey[0]}`}
                            colon={false}
                            label={<span>
                                {fields.label+" :"}
                                {(fields.browserConditionParam.viewAttr == 1 ? "" :
                                <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@xy7l82@${fields.domkey[0]}`} placement="bottom" title={getLabel(383844,"项目人员默认保存时将任务负责人同步至项目成员")}>
                                    <span className={`icon-coms-Explain`} style={{marginLeft:"10px",color:"#fa0",fontSize:"14px"}} />
                                </Tooltip>)}
                            </span>}
                            labelCol={{span: `${fields.labelcol}`}}
                            error={form.getError(fields)}
                            tipPosition="bottom"
                            wrapperCol={{span: `${fields.fieldcol}`}} >
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@lgbbaj@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams}/>
                            </WeaFormItem>),
                        colSpan:1,
                        hide:hide
                    });
                }
                
            }else{
                if(hasunderline){
                      items.push({
                        com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@hid7t0@${fields.domkey[0]}`}
                            label={`${fields.label}`}
                            labelCol={{span: `${fields.labelcol}`}}
                            error={form.getError(fields)}
                            tipPosition="bottom"
                            wrapperCol={{span: `${fields.fieldcol}`}} underline>
                                {dom}
                            </WeaFormItem>),
                        colSpan:1,
                        hide:hide
                    });
                }else{
                    items.push({
                        com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@tp73ab@${fields.domkey[0]}`}
                            label={`${fields.label}`}
                            labelCol={{span: `${fields.labelcol}`}}
                            error={form.getError(fields)}
                            tipPosition="bottom"
                            wrapperCol={{span: `${fields.fieldcol}`}}>
                                {dom}
                            </WeaFormItem>),
                        colSpan:1,
                        hide:hide
                    });
                }
            }
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@dqv5z0@${i}`} needTigger={true} title={c.title} col={1} showGroup={c.defaultshow} items={items}/>)
        });
        return group;
    }
}



